﻿using CollegeApp.Data.IDataAdapters.Adapters;
using CollegeApp.Data.IDataAdapters.Interfaces;
using CollegeApp.DataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CollegeApp.Web.Controllers
{
    public class HomeController : Controller
    {
        //Declaring local instance of an adapter
        ICollegeAdapter _adapter;
        //Declare the Home Controller Constructors:

        //Default Constructor
        public HomeController()
        {
            _adapter = new CollegeAdapter();
        }
        //Overload for testing
        public HomeController(ICollegeAdapter adapter)
        {
            _adapter = adapter;
        }
        public ActionResult Index()
        {
            List<College> colleges = _adapter.GetAllColleges();
            return View(colleges);
        }

        public ActionResult Details(int id)
        {
            return View();
        }
        [HttpGet]
        public ActionResult AddCollege()
        {
            return View();
        }
        [HttpPost]
        public ActionResult AddCollege(string name, string image)
        {
            College college = new College();
            college.Name = name;
            college.Image = image;
            college = _adapter.AddCollege(college);
            return RedirectToAction("Details/" + college.Id);
        }

    }
}